<html>
<head><meta charset="utf-8"><title>How can I get the fully qualified path to a type? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html">How can I get the fully qualified path to a type?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218221143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218221143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218221143">(Nov 29 2020 at 17:23)</a>:</h4>
<p>Since <a href="https://github.com/rust-lang/rust/pull/73996">https://github.com/rust-lang/rust/pull/73996</a> I can't make heads nor tails of the pretty-printing system. If I have a type from <code>tcx.type_of(def_id)</code>, how can I print its fully qualified path?</p>



<a name="218221146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218221146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218221146">(Nov 29 2020 at 17:23)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="244331">@Dan Aloni (da-x)</span></p>



<a name="218221243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218221243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218221243">(Nov 29 2020 at 17:26)</a>:</h4>
<p>currently I'm using this but it seems like a hack:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">                </span><span class="kd">let</span><span class="w"> </span><span class="n">ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">cx</span><span class="p">.</span><span class="n">tcx</span><span class="p">.</span><span class="n">type_of</span><span class="p">(</span><span class="n">self_id</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="kd">let</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">ty</span><span class="p">.</span><span class="n">kind</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="n">TyKind</span>::<span class="n">Adt</span><span class="p">(</span><span class="n">def</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">cx</span><span class="p">.</span><span class="n">tcx</span><span class="p">.</span><span class="n">item_name</span><span class="p">(</span><span class="n">def</span><span class="p">.</span><span class="n">did</span><span class="p">).</span><span class="n">to_string</span><span class="p">()),</span><span class="w"></span>
<span class="w">                    </span><span class="c1">// TODO: not sure if this will work</span>
<span class="w">                    </span><span class="n">other</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">other</span><span class="p">.</span><span class="n">is_primitive</span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">ty</span><span class="p">.</span><span class="n">to_string</span><span class="p">()),</span><span class="w"></span>
<span class="w">                    </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">None</span><span class="p">,</span><span class="w"></span>
<span class="w">                </span><span class="p">};</span><span class="w"></span>
</code></pre></div>



<a name="218223327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Aloni (da-x) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223327">(Nov 29 2020 at 18:20)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span>  Did you try the <code>with_no_trimmed_paths(|| .. )</code> wrapper?</p>



<a name="218223330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223330">(Nov 29 2020 at 18:20)</a>:</h4>
<p>where can I find that?</p>



<a name="218223337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Aloni (da-x) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223337">(Nov 29 2020 at 18:21)</a>:</h4>
<p><code>use rustc_middle::ty::print::with_no_trimmed_paths;</code></p>



<a name="218223341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223341">(Nov 29 2020 at 18:21)</a>:</h4>
<p>thanks! Can you document this somewhere, maybe on <code>Ty</code> or <code>TyS</code>?</p>



<a name="218223350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223350">(Nov 29 2020 at 18:21)</a>:</h4>
<p>just a link to <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/print/index.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/print/index.html</a> would be fine I think</p>



<a name="218223353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Aloni (da-x) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223353">(Nov 29 2020 at 18:21)</a>:</h4>
<p>Although, it's a bit surprising that <code>.to_string()</code> doesn't work for you, <del>as the <code>Display</code> impl of pretty printing uses it internally</del>.</p>



<a name="218223393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223393">(Nov 29 2020 at 18:22)</a>:</h4>
<p>well it does work, it just doesn't use the correctly scoped paths</p>



<a name="218223399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223399">(Nov 29 2020 at 18:22)</a>:</h4>
<p>I don't have the exact error on me, I'd have to rebuild rustdoc</p>



<a name="218223401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223401">(Nov 29 2020 at 18:22)</a>:</h4>
<p>it was using the scope of the crate root instead of the current module</p>



<a name="218223427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Aloni (da-x) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223427">(Nov 29 2020 at 18:23)</a>:</h4>
<p>Not sure I understand</p>



<a name="218223430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Aloni (da-x) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223430">(Nov 29 2020 at 18:23)</a>:</h4>
<p>If you want the scope of the current module? I'm not sure it can be considered 'fully qualified'</p>



<a name="218223472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223472">(Nov 29 2020 at 18:24)</a>:</h4>
<p>well right, it needs to be either fully qualified or the current scope</p>



<a name="218223476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223476">(Nov 29 2020 at 18:24)</a>:</h4>
<p>but not a <em>different</em> scope</p>



<a name="218223578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223578">(Nov 29 2020 at 18:26)</a>:</h4>
<p>hmm, with_no_trimmed_paths didn't work either:</p>
<div class="codehilite"><pre><span></span><code>warning: unresolved link to `sync::condvar::Condvar::notify_all`
   --&gt; library/std/src/sync/condvar.rs:475:25
    |
475 |     /// [`notify_all`]: Self::notify_all
    |                         ^^^^^^^^^^^^^^^^ no item named `sync` in scope
</code></pre></div>



<a name="218223581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Aloni (da-x) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223581">(Nov 29 2020 at 18:26)</a>:</h4>
<p>Sorry, I forgot - <code>Debug</code> trait will give you the full path, not <code>Display</code>.</p>



<a name="218223686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223686">(Nov 29 2020 at 18:29)</a>:</h4>
<p>so the issue here is that <code>sync</code> should not be showing up as the first path: it should be either <code>crate::sync::condvar::Condvar</code> (which is fine) or just <code>Condvar</code></p>



<a name="218223688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223688">(Nov 29 2020 at 18:29)</a>:</h4>
<p>but the weird mix means the scopes are wrong</p>



<a name="218223764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223764">(Nov 29 2020 at 18:30)</a>:</h4>
<p>anyway, this is fundamentally hacky so maybe I shouldn't be surprised it doesn't work by default <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="218223767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223767">(Nov 29 2020 at 18:30)</a>:</h4>
<p>I want to go from DefId -&gt; String and back again</p>



<a name="218223781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dan Aloni (da-x) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223781">(Nov 29 2020 at 18:31)</a>:</h4>
<p>There's the <code>with_crate_prefix</code> wrapper, BTW</p>



<a name="218223896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223896">(Nov 29 2020 at 18:33)</a>:</h4>
<p>because the alternative was this monster that sat idle for 3 months: <a href="https://github.com/jyn514/rust/tree/intra-link-self-big-refactor">https://github.com/jyn514/rust/tree/intra-link-self-big-refactor</a></p>



<a name="218223900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218223900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218223900">(Nov 29 2020 at 18:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="244331">Dan Aloni (da-x)</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F/near/218223781">said</a>:</p>
<blockquote>
<p>There's the <code>with_crate_prefix</code> wrapper, BTW</p>
</blockquote>
<p>ooh, that looks great, thanks!</p>



<a name="218224075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20can%20I%20get%20the%20fully%20qualified%20path%20to%20a%20type%3F/near/218224075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20can.20I.20get.20the.20fully.20qualified.20path.20to.20a.20type.3F.html#218224075">(Nov 29 2020 at 18:37)</a>:</h4>
<p>ok yeah that fixed it :) thanks so much for the help!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>